#!/bin/bash
export jar_name=$1
export port=$2
export java_home=/usr/java/jdk1.8.0_172
shutdown_second=5
echo "jar_name is ${jar_name}, port is ${port}"

pid="`${java_home}/bin/jps -l | grep ${jar_name} | awk '{print $1}'`"
echo "pid is ${pid}"

if [ -n "${pid}" ]
then
   kill -9 ${pid}
   sleep ${shutdown_second}
fi

cp   /root/.jenkins/workspace/microserver/target/${jar_name} /opt/script/
cd /opt/script/
chmod +x ${jar_name}
echo "start ${jar_name} process"
nohup  ${java_home}/bin/java -jar  -Dserver.port=${port}  ${jar_name}  > /opt/script/log/${jar_name}.log &

echo "end ${jar_name} process"
